class MyPlugin {
    apply (compiler) {
        compiler.hooks.emit.tap('MyPlugin', complation => {
            for (const name in complation.assets) {
                if (name.endsWith('.js')) {
                    const contents = complation.assets[name].source()
                    let withoutComments = contents.replace(/\/\*\*+\*\//g, '') // 去掉/******/
                    withoutComments = withoutComments.replace(/\/\/.*/g, '') // 去掉单行注释
                    withoutComments = withoutComments.replace(/(\/\*\s).*(\*\/)/, '').replace(/(\/\*\*\s).*(\*\/)/, '').replace(/(\/\*\*)(.|\n)*(\*\/)/, '') // 去掉多行注释
                    complation.assets[name] = {
                        source: () => withoutComments,
                        size: () => withoutComments.length
                    }
                }
            }
        })
    }
}
module.exports = MyPlugin